package com.neo.office.server.exception;

import com.neo.office.server.config.data.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;

@RestControllerAdvice
public class GlobalException {

    @ExceptionHandler(SQLException.class)
    public Result mysqlException(SQLException sqle){
        if (sqle instanceof SQLIntegrityConstraintViolationException){
            return Result.error("改数据库有关联数据，操作失败！");
        }
        return Result.error("数据库异常，操作失败");
    }
}
